Parse table generation method and system

ABSTRACT

A method and system assembles state transition tables ( 100 ) from a plurality of modular sub-tables ( 102 ). In one embodiment, each sub-table ( 102 ) defines an individual statement in a programming language. Combining multiple sub-tables ( 102 ) together into one large table ( 100 ) creates a dictionary for a programming language that can be used to, for example, compile code into the programming language or translate code from one language to another. Using sub-tables ( 102 ) simplifies construction of the larger table ( 100 ) and makes it easier to add, modify, or remove portions of the table ( 102 ).

TECHNICAL FIELD

[0001] The present invention relates to state transition tables, and more particularly to a state transition table constructed from a plurality of sub-tables.

BACKGROUND OF THE INVENTION

[0002] Code compilers and code translation systems, such as the translation system described in commonly-assigned, co-pending U.S. application Ser. No. ______ (Attorney Docket No. 67010-032), the disclosure of which is incorporated by reference in its entirety, often use state transition tables for defining outputs corresponding to given inputs. For example, a compiler may receive a data item and access a state transition table based on the data item's type and the current state to obtain a new state and an action (if any) to perform on the data item.

[0003] As the number of possible states and data item types increases, however, the state transition table becomes large and unwieldy. Editing the table is impractical due to its size, and it can be difficult to add new functions to the table to accommodate new data items or change table actions for old data items. Further, constructing large tables in the first instance is often difficult because it requires a programmer to keep track of many variables at once, providing no mechanism for dividing the task into smaller parts.

[0004] There is a desire for a system that can simplify the creation and maintenance of state transition tables.

SUMMARY OF THE INVENTION

[0005] Accordingly, one embodiment of the invention is directed to a method and system that generates state transition tables from a plurality of modular sub-tables. In one embodiment, each sub-table defines an individual statement in a programming language. Combining multiple sub-tables together into one large table therefore creates a dictionary for a programming language that can be used to, for example, compile code into the programming language or translate code from one language to another.

[0006] By constructing a state transition table from multiple sub-tables, the invention makes it easier to construct and edit large tables containing many statements. New statements may also be added to the table easily by incorporating additional sub-tables into the large table.

BRIEF DESCRIPTION OF THE DRAWINGS

[0007]FIG. 1 is a representative block diagram illustrating a table structure generated according to one embodiment of the invention;

[0008]FIGS. 2A and 2B illustrate examples of possible sub-tables created according to one embodiment of the invention; and

[0009]FIG. 3 is a flow diagram illustrating a process using a table constructed according to one embodiment of the invention.

DETAILED DESCRIPTION OF THE EMBODIMENTS

[0010]FIG. 1 is a block diagram representing a table 100 generated according to one embodiment of the invention. The table 100 is generally a state transition table similar to those known in the art. In the invention, however, the table 100 is constructed from two or more sub-tables 102, each sub-table 102 acting as a building block for the overall table 100. In one embodiment, each sub-table 102 defines a particular programming statement or syntax for a given programming language. More particularly, each sub-table 102 for a given statement or syntax contains only words and symbols, or “tokens”, necessary to define that statement or syntax. All of the sub-tables 102 taken together define a group of statements and syntaxes and therefore act as a dictionary for a complete programming language.

[0011]FIGS. 2A and 2B are examples of possible sub-tables 102 used in the invention. These particular examples define terms found in PL/SQL language, but any language may be defined by the sub-tables 102 without departing from the scope of the invention. FIG. 2A illustrates a sub-table 102 defining a SELECT statement in PL/SQL language, while FIG. 2B illustrates a sub-table 102 defining a keyword builder that may be used by, for example, a scanner that receives a plurality of characters and builds words or statements corresponding to a given language from those characters. Although the description below will focus on the example shown in FIG. 2A, the same principles apply to both FIGS. 2A and 2B.

[0012] Referring to FIG. 2A, the sub-table 102 defines a plurality of lettered relocatable states 200. The states 200 in the sub-table 102 are relocatable because the final state positions within the overall table 100 are unknown at the time the sub-tables 102 are written. In one embodiment, each sub-table 102 starts with an initial state 201 (defined as “state 1” in this example) and the token(s) that would be found at the beginning of the statement defined by the sub-table 102. For example, as shown in FIG. 2A, a SELECT statement would normally begin with the word SELECT, and therefore a parse tool would carry out the action defined at the SELECT token in state 1 first.

[0013] The sub-table 102 also maps one or more possible tokens 202 that define the statement or syntax described by the sub-table 102. In the example shown in FIG. 2A, the SELECT statement may be defined by keywords such as INTO, VALUES, FROM and SET as well as punctuation marks or a program variable (“A” in this example). The sub-table 102 may also include a default token (Φ in this example) that represents a default transition to cover any token/state combinations not explicitly mapped in the sub-table 102. In one embodiment, the sub-table 102 only maps tokens 202 that require unique actions and provides the default token to handle all other received tokens. This allows the sub-table 102 to be kept relatively short and simple while still including a general token/state combination to handle any unexpected situations.

[0014] For at least one state 200, 201 and token 202 combination, the sub-table 102 defines a state change and/or action 204. When the table 100 is being used (e.g., during a scanning, parsing, or compiling operation), each operation will start in a given fixed state 1. The next token found determines the next state transition, which would lead to states in one of the sub-tables 102. For example, if a parsing tool receives a SELECT statement, the transition from state 1 would direct the parsing tool to the first relocatable state (“A”) fromfrom the sub-table 102 corresponding to the SELECT statement. In this case, the sub-table 102 instructs the tool to change the current state to state A and carry out action 36 (an action defined in, for example, an action table or code generator). The tool then continues receiving additional tokens, changing state and carrying out actions based on the received tokens and the current state. If the action corresponding to a present state/token combination is zero or blank in the sub-table 102, the tool may carry out the default transition for that state. When the parsing action for a given statement is complete, the parsing tool returns to state 1 and readies itself to receive another statement and access the sub-table 102 corresponding to the statement.

[0015] When the sub-tables 102 are assembled together to form the complete table 100, the lettered relocatable states 200 defined in the sub-tables 102 may be redefined as numerical states in the context of the overall array. For example, states A through F in the SELECT statement (FIG. 2A) may be redefined as states 81 through 86 in the overall table 100 if there are 80 other states defined in sub-tables 102 appearing in the table 100 before the SELECT statement sub-table. The references to the lettered relocatable states corresponding to actions 204 in the sub-tables 102 are mapped to these numerical states. For example, if the sub-table directs a transition to state B, it would be stored as a reference to state 82 in this example. Thus, each state in the overall table 100 will have its own unique state number.

[0016] Constructing the overall table 100 using sub-tables 102 makes it easy to add programming terms as the need arises because each sub-table 102 is a discrete module that can be independently generated and incorporated into the main table 100. Breaking the table 100 into sub-tables 102 makes it easier to edit the table 100 and to keep programming of the overall table organized as well. Modifying the table 100 would entail only identifying the particular statement requiring modification, locating the sub-table 102 associated with that statement, and editing the sub-table 102. The resulting edited table 100 may then be recompiled if needed to accommodate the changes to the sub-table 102 (e.g., renumber the states).

[0017]FIG. 2B incorporates concepts similar to those described above in FIG. 2A, but the sub-table 102 in FIG. 2B is used to build strings, such as keywords, that may themselves be incorporated into another sub-table. Where the resulting table from FIG. 2A would be used by a parser, the table from FIG. 2B would be used by a scanner, a lower-level operation where tokens are formed from the input language being processed. The resulting tokens could then be the input to a parser and recognized as keywords or other higher-level tokens

[0018]FIG. 3 is a flow diagram illustrating one example of a process 300, such as a parsing, scanning, or compiling process, that accesses a table 100 constructed according to one embodiment of the invention. As noted above, the table 100 contains a plurality of sub-tables 102. When an application tool, such as a parser, scanner or compiler, receives a statement (block 302), it accesses the sub-table corresponding to that statement, starting at the initial state (e.g., state 1) in that sub-table (block 304). The tool then receives individual tokens corresponding to the statement and carries out actions based on each token and the current state, as explained above (block 306). Once an action for a token is carried out, the tool continues to processprocess additional tokens for the current statement (block 308) until it reaches the end of the statement and the table directs return to return to the initial state (block 310). It would continue to process tokens, parsing a new statement (block 302) and would accessaccess the sub-table corresponding to the new statement. In essence, each sub-table 102 acts like a sub-routine for a larger programming application, with the tool accessing individual, independent sub-tables 102 as needed.

[0019] As a result, the invention creates state transition tables by defining individual sub-tables that can later be assembled to complete a complete table, such as a parse table, scanner table, or compiler table. The constructed tables can be used in any application that uses state transition tables, such as compilers or code translation systems. Further, the inventive modular technique can be used as a tool to create other programs.

[0020] Note that although the above example discusses a parse table, the same technique can be used to construct any state transition table (e.g., an action table, a scanner table, etc.) that has two-dimensional arrays containing actions for a plurality of different states and possible token types and that can be broken down into independently-accessible sub-tables.

[0021] It should be understood that various alternatives to the embodiments of the invention described herein may be employed in practicing the invention. It is intended that the following claims define the scope of the invention and that the method and apparatus within the scope of these claims and their equivalents be covered thereby. 

What is claimed is:
 1. A state transition table defining a plurality of statements in a programming language, each statement defined by at least one token, comprising: a plurality of sub-tables, each sub-table corresponding to one of said plurality of statements, wherein each sub-table is a two-dimensional array defining an action for at least one token in at least one state.
 2. The state transition table of claim 1, wherein at least one sub-table contains a default token representing a default action.
 3. The state transition table of claim 1, wherein said at least one state in the sub-table is initially defined as a relocatable state.
 4. The state transition table of claim 4, wherein said at least one relocatable state is redefined when the plurality of sub-tables are assembled to form the state transition table.
 5. The state transition table of claim 1, wherein each sub-table has an initial state at which access of the sub-table begins.
 6. The state transition table of claim 1, wherein the state transition table is one selected from the group consisting of a scanner table, a parser table, and a compiler table.
 7. A method for accessing a state transition table defining a plurality of statements in a programming language, each statement defined by at least one token, comprising: receiving one of said plurality of statements; accessing a sub-table in the state transition table, wherein the accessed sub-table corresponds to the received statement; receiving a token corresponding to the received statement; accessing the sub-table corresponding to the received statement based on the received token and a current state; and carrying out an action corresponding to the received token and the current state.
 8. The method of claim 8, further comprising: receiving a second one of said plurality of statements; and accessing a second sub-table corresponding to the second received statement.
 9. A method of generating a state transition table defining a plurality of statements in a programming language, comprising: generating a plurality of sub-tables, each sub-table corresponding to one of said plurality of statements; and assembling said plurality of sub-tables together to generate the state transition table.
 10. The method of claim 9, wherein each sub-table defines at least one relocatable state, and wherein the method further comprises redefining said at least one relocatable state during the assembling act. 